package org.iabako.server.dao.business;

import org.iabako.server.dao.JpaDAO;
import org.iabako.shared.entity.business.ClientCommunication;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by jose on 03/02/15.
 */
@Repository("clientCommunicationDAO")
public class ClientCommunicationDAO extends JpaDAO<Long, ClientCommunication> {

    @Override
    protected String getUniqueNumberVerificationQuery() {
        return null;
    }

    @Override
    protected String getLastNumberQuery() {
        return null;
    }

    public void addClientCommunications(Map<ClientCommunication, List<Long>> clientCommunicationsMap) {

        String query = "INSERT INTO CLIENT_COMMUNICATION (ID_COMMUNICATION, ID_CLIENT) VALUES (:idCommunication, :idClient)";

        for (ClientCommunication comm : clientCommunicationsMap.keySet()) {
            for (Long idClient : clientCommunicationsMap.get(comm)) {
                entityManager.createNativeQuery(query).setParameter("idCommunication", comm.getId()).
                        setParameter("idClient", idClient).executeUpdate();
            }
        }
    }
}
